<?php 
	  if(1==2){$HttpResult = new HttpResult();}
	  $HttpContentResult = $HttpResult->getHttpContentResult();
//	  Debug::print_r($HttpResult);exit();
		$head = new HtmlHeader($HttpContentResult->getHeader());    
		$head->addCSS(array('reset','admin'));
		$head->addCSS('print','', 'print');
		$head->addCSS('ie',  'css/ie', 'print',true);
		
		//<!-- SWF OBJECT -->
		$head->addJS('swo', 'js/swfobject/swfobject');
		
		//<!-- PROGRAMACAO JS | JQUERY  -->
		$head->addJS(array('jquery', 'masked','admin', 'order_admin'));
		//MENU DROPDOWN
    $head->addJS('Menu principal','js/menu/ddsmoothmenu');
    $head->addCSS('Menu CSS','js/menu/ddsmoothmenu');
		//<!-- JQUERY UI  -->
		$head->addJS('UI', 'js/UI/js/jquery-ui-1.8.6.custom.min');
		$head->addCSS('UI','js/UI/css/smoothness/jquery-ui-1.8.6.custom');
		$head->addJS('UI_TIME','js/UI/js/timepicker');
		
		//<!-- TABLE SORTER -->
		$head->addJS('tablesorter', 'js/tablesorter/tablesorter');
		$head->addCSS('tablesorter', 'js/tablesorter/tablesorter');
		
		$head->addCSS('democrart_adm');
		
		$header_html = $head->show(TRUE);
$header_html = str_replace(array("democrart", "democrArt", "Democrart", "DemocrArt"), array("expressaoartistica", "Expressão Artística", "Expressão Artística", "Expressão Artística"), $header_html);
echo $header_html;
		
		
		$VO = $HttpContentResult->std_vo;
		//Debug::print_r($VO);	
?>
 
<body>

<div id="main">
      <?php include "view/democrart/parts/admin/header.php" ?>
      
	  <div id="main_content" class="purchase_order">
	  
	  <div id="msgBox"></div>
	  			
		 <div id="box_right">
			<h1 style="margin-bottom:50px;font-size:16px">Detalhes do pedido</h1>
									
			
				<div class='block'>
					<ul class="column two">
					
						<li>
							<h1>Número do Pedido: <?php echo $VO->id ; ?></h1>
							<h2>Cliente</h2>
							<p><?php echo $VO->recipient_name;// . " ".$VO-> ?></p>
							<h3><i><a class="btn" href="<?php echo Config::getRootPath("admin/client/update/id." . $VO->user_id); ?>">Clique aqui para ver os detalhes do cliente</a></i></h3>
							<input type="hidden" name="id" id="idStatus" value="56554" />
						</li>
						
						<li>
							<h1>Data do Pedido: <?php echo DataHandler::convertDateToBrazil($VO->date_order); ?></h1>
							<h2>Endereço de Entrega</h2>
							<p><?php echo $VO->recipient_city , ' - ', $VO->recipient_state ;?></p>
							<p>CEP: <?php echo $VO->recipient_zip_code ;?></p>
							<p><?php echo $VO->recipient_address ;?></p>
						</li>
						
						<li>
							<h2>Observação do cliente:</h2>
							<p>
								<?php echo strlen($VO->note)>0 ?  $VO->note : 'Nenhuma observação fornecida pelo cliente'; ?>
							</p>
						</li>
					</ul>
				</div>
				<div class='block'>
					<ul class="box" style="width:400px;line-height: 20px">
						<li>
							<h2>Parceiro indicado: <?php echo ucfirst($VO->partner_vo->name); ?></h2>
						</li>
						<li>
							<h2>Total de itens: <?php echo count($VO->array_itens); ?></h2>
						</li>
						<li>
							<span style="float:left;font-weight: bold">Método de entrega:</span> <?php echo $VO->shipping_type_name; ?>
						</li>
					</ul>
	
					<ul class="box right" style="line-height: 20px">
							<?php if(isset($VO->coupon->valor_total)){?>
							<li>
								<span style="float:left;font-weight: bold">Valor Total:</span> <?php echo DataHandler::convertMoneyToBrazil($VO->coupon->valor_total); ?>
							</li>
							<?php }?>
							<?php if(isset($VO->coupon->id) && $VO->coupon->id>0){ ?>
							<li>
								<span style="float:left;font-weight: bold">Valor Cupom:</span> - <?php echo DataHandler::convertMoneyToBrazil($VO->coupon->valor_desconto); ?>
							</li>
							<?php }?>
							<li>
								<span style="float:left;font-weight: bold">Subtotal:</span> <?php echo DataHandler::convertMoneyToBrazil($VO->total_value); ?>
							</li>
							<li>
								<label style="float:left;font-weight: bold">Valor do Frente</label>
								<?php echo DataHandler::convertMoneyToBrazil($VO->shipping_value); ?>
							</li>
							<li>
							<h2>Total: <?php echo DataHandler::convertMoneyToBrazil($VO->pay_value); ?></h2>
						</li>
					</ul>
				</div>
				<div style="width:640px;">
				<?php 
						$new_status_id = 0;
						if($VO->active == PurchaseOrderDAO::STATUS_NOT_CONCLUED){
							$new_status_id = 1;
						}
						if($VO->active == PurchaseOrderDAO::STATUS_NOT_FINISHED){
							$new_status_id = 2;
						}
						if($VO->active == PurchaseOrderDAO::STATUS_FINISHED){
							$new_status_id = 0;
						}
						
					?>
					<form method="post" id='change_status_form'>
						<input type="hidden" name="action" value="change_status" />
						<input type="hidden" name="new_status" value="<?php echo $new_status_id ; ?>" />
					</form>
					<?php if($new_status_id == 1){?>
						<span class="button" id='changePurchaseOrderStatus'><?php echo 'Marcar como Aguardando'; ?></span>
					<?php }?>
					<?php if($new_status_id == 2){?>
						<span class="button" id='changePurchaseOrderStatus'><?php echo 'Marcar como Finalizado'; ?></span>
					<?php }?>
					<?php if($new_status_id == 0){?>
						<span class="button" id='changePurchaseOrderStatus'><?php echo 'Marcar como Não Finalizado'; ?></span>
					<?php }?>
						<span style="text-align: right;" onclick="printDiv('box_right')" class="button print">Imprimir pedido...</span>
					
				</div>
				<div class='block'>
				
					<h2 style="padding: 15px 0">Histórico do Pedido</h2>
					<table class="tabela">
						<thead>
							<tr>
								<th>Descrição</th>
								<th>Data</th>
								<th class="action" >Ação</th>
							</tr>
						</thead>
						<?php foreach ($VO->all_status as $status):?>
							<tr>
								<td>
								
									<input name="status_description" id="status_description<?php echo $status->id ?>" type="text" value = "<?php echo $status->title , ' ', $status->description; ?>" class="readyOnly" readonly="readonly" />
								
								</td>
								
								<td>
									<input name="status_date" id="status_date<?php echo $status->id ?>" type="text" value = "<?php echo DataHandler::convertDateToBrazil($status->date); ?>"  class="readyOnly" readonly="readonly" />
								</td>
								
								<td class="action" style="text-align: center;">
									<img class="btAction" src="<?php echo Config::getAsset("assets/img/icons/edit.jpg")?>"  id='edit_purchase_status<?php echo $status->id  ?>' alt="Editar" title=""/>
									<img class="btAction" src="<?php echo Config::getAsset("assets/img/icons/excluir.gif")?>" id='delete_purchase_status<?php echo $status->id ?>' alt="Excluir" title=""  />
								</td>
							
							</tr>
							
						<?php endforeach; ?>
					</table>
					
						<form method="post" id='statusForm'>
							<input type="hidden" name='action' value='update_status' />
							<h2>Novo status do pedido</h2>
							<table class="status">
								<tr>
									<th>Status</th>
									<th>Data/Hora</th>
								</tr>
								<tr>
									<td>
										<select id="selStatus" name='status' class="filter input;">
											<?php foreach ($VO->array_def_status as $opt): ?>
												<option value="<?php echo $opt->title;?>"><?php echo $opt->title;?></option>
											<?php endforeach; ?>
											<option value="custom">Outros</option>
										</select>
					
									</td>
									<td>
										<input type="text" name="date" id="dtStatus" class="dtStatus" />
									</td>
								</tr>
								<tr>
									<td colspan="3">
										<input type="text" name="status_custom" id="status" style="display: none;width:100%;margin-bottom:15px" value="" />
									</td>
								</tr>
								<tr>
									<td colspan="3"  style="padding: 10px 0;text-align: right;"><span style="margin-right: 10px" class="button" id="btAddStatus">Atualizar Histórico</span></td>
								</tr>
							</table>
						</form>
						
					</div>
					
					<ul class="column one" >
					<li style="padding-top: 10px" >
						<h2>Pagamentos:</h2>
						<?php if(!count($VO->array_payment) >0):?>
							<span>Nenhum pagamento registrado</span>
						<?php else: ?>
						<table class="tabela" style="width: 100%" id="table_payment">
							<thead>
								<tr>
									<th>Status</th>
									<th>Tipo de pagamento</th>
									<th>Valor</th>
									<th>Ação</th>
								</tr>
							</thead>
							<?php foreach($VO->array_payment as $payment): ?>
								<tr>
									<td><?php echo ($payment->date_confirm == NULL ? "não confirmado" :  'confirmado em :' . DataHandler::convertDateToBrazil($payment->date_confirm) ); ?></td>
									<td><?php echo $payment->payment_type_name; ?></td>
									<td><?php echo DataHandler::convertMoneyToBrazil($payment->total_value); ?></td>
									<td style="text-align: center;vertical-align: middle;" ><img class="btAction" src="<?php echo Config::getAsset("assets/img/icons/excluir.gif")?>" alt="Excluir" title="" id="delete_payment<?php echo $payment->id; ?>" /></td>
								</tr>
							<?php endforeach; ?>
						</table>
						<?php endif; ?>

						<span style="float:right;margin-bottom: 5px" class="button" id='show_form_add_payment'>Adicionar confirmação de pagamento</span>

						<div class='block' id='form_add_payment' style="display:none">
							<form method="post" id='paymentForm'>
								<input type="hidden" name='action' value='add_payment' />
								<h2>Novo pagamento do pedido</h2>
								<table class="tabela">
									<tr>
										<th>Forma de pagamento</th>
										<th>Data</th>
										<th>valor Total</th>
									</tr>
									<tr>
										<td>
											<select id="selStatus" name='payment_type_id' class="filter input;" >
												<?php foreach ($VO->array_pay_type as $opt): ?>
													<option value="<?php echo $opt->id;?>"><?php echo $opt->name;?></option>
												<?php endforeach; ?>
											</select>
										</td>
										<td>
											<input type="text" name="date_confirm" class="dtStatus" />
										</td>
										<td>
											<input type="text" name="value" />
										</td>
										
									</tr>
									<tr>
										<td colspan="3"><span style="float: right;margin: 10px 0" class="button" id="btAddPayment">Atualizar</span></td>
									</tr>
								</table>
							</form>
							
						</div>
					</li>
				</ul>
				
				<div>
						<h2 style="margin-top:15px;display:block" >Itens</h2>
												
						<table class="tabela">
							<thead>
								<tr>
									<th>SKU</th>
									<th>Descrição</th>									
									<th>Preço</th>
								</tr>
							</thead>
							
							<tbody>
								<?php foreach ($VO->array_itens as $item): ?>
									<tr>
										<td><?php echo $item->product_sku; ?></td>
										<td><?php echo $item->quantity, ' - ', $item->product_name, ' ' , $item->product_description; ?></td>
										<td><?php echo DataHandler::convertMoneyToBrazil($item->total_price); ?></td>
									</tr>
								<?php endforeach; ?>
							</tbody>
						</table>
						
				</div>
				<?php if(isset($VO->coupon->id) && $VO->coupon->id>0){ ?>				
				<div>
						<h2 style="margin-top:15px;display:block" >Cupons</h2>
												
						<table class="tabela">
							<thead>
								<tr>
									<th>Titulo</th>
									<th>Token</th>									
									<th>Value</th>
								</tr>
							</thead>

							<tbody>

									<tr>
										<td><?php echo $VO->coupon->title; ?></td>
										<td><?php echo $VO->coupon->token; ?></td>
										<td><?php echo DataHandler::convertMoneyToBrazil($VO->coupon->valor_desconto); ?></td>
									</tr>

							</tbody>
						</table>
				</div>
				<?php } ?>					
		</div>
					
			
			<!-- FIM DO QUADRO -->
	
	</div>
	
</div>

</body>
</html>
